package com.zh.work.controller.platform.trans;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.entity.JSONResult;
import com.zh.work.entity.trans.QuickTransHistoryEntity;
import com.zh.work.entity.trans.QuickTransTodayEntity;
import com.zh.work.service.platform.trans.QuickTransHistoryService;
import com.zh.work.service.platform.trans.QuickTransTodayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 快捷交易控制器
 * @Author: Li.HuiNeng
 * @Create in: 2020-01-07 14:04
 * @Version: 1.0.1
 */
@Api(value = "快捷交易控制器", produces = "application/json", tags = {"快捷订单交易控制器"})
@RestController
@RequestMapping("/quickTrans")
public class QuickTransController {

    @Autowired
    private QuickTransTodayService serviceToday;

    @Autowired
    private QuickTransHistoryService serviceHistory;

    @ApiOperation(value = "分页查询快捷实时交易数据集", tags = {"getQuickTransTodayPages"}, notes = "分页查询快捷实时交易数据集")
    @GetMapping("/getQuickTransTodayPages")
    public JSONResult<List<QuickTransTodayEntity>> getQuickTransTodayPages(
            @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
            @ApiParam(value = "当前页显示数量", name = "pageNo") Integer pageSize,
            @ApiParam(value = "快捷今日交易实体类", name = "quickTransTodayEntity") QuickTransTodayEntity quickTransTodayEntity) {
        JSONResult<List<QuickTransTodayEntity>> jsonResult = new JSONResult<>();
        try {
            Page<QuickTransTodayEntity> page = new Page<>(pageNo, pageSize);
            IPage<QuickTransTodayEntity> result = serviceToday.getQuickTransTodayPages(page, quickTransTodayEntity);
            jsonResult.setTotal(page.getTotal());
            jsonResult.setData(result.getRecords());
            jsonResult.setMessage("操作成功");
            jsonResult.setSuccess(true);
            jsonResult.setCode(200);
        } catch (Exception e) {
            jsonResult.setMessage(e.getLocalizedMessage());
            jsonResult.setSuccess(false);
            e.printStackTrace();
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页查询快捷历史交易数据集", tags = {"getQuickTransHistoryPages"}, notes = "分页查询快捷历史交易数据集")
    @GetMapping("/getQuickTransHistoryPages")
    public JSONResult<List<QuickTransHistoryEntity>> getQuickTransHistoryPages(
            @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
            @ApiParam(value = "当前页显示数量", name = "pageNo") Integer pageSize,
            @ApiParam(value = "快捷历史交易实体类", name = "quickTransHistoryEntity") QuickTransHistoryEntity quickTransHistoryEntity) {
        JSONResult<List<QuickTransHistoryEntity>> jsonResult = new JSONResult<>();
        try {
            Page<QuickTransHistoryEntity> page = new Page<>(pageNo, pageSize);
            IPage<QuickTransHistoryEntity> result = serviceHistory.getQuickTransHistoryPages(page, quickTransHistoryEntity);
            jsonResult.setTotal(page.getTotal());
            jsonResult.setData(result.getRecords());
            jsonResult.setMessage("操作成功");
            jsonResult.setSuccess(true);
            jsonResult.setCode(200);
        } catch (Exception e) {
            jsonResult.setMessage(e.getLocalizedMessage());
            jsonResult.setSuccess(false);
            e.printStackTrace();
        }
        return jsonResult;
    }
}
